package it.wzm.lightweightlogx;


import java.sql.PreparedStatement;
import java.util.Properties;
import it.wzm.lightweightlog.DBDumper;
import it.wzm.lightweightlog.DumperException;
import it.wzm.lightweightlog.Entry;
import it.wzm.lightweightlog.annotation.DumpingProcessor;

@DumpingProcessor(active=false)
public class XDBDumper extends DBDumper {

	/**
	 * As required by serialization
	 */
	private static final long serialVersionUID = 1693145459349955269L;
	
	/**
	 * Constructor
	 * @param p
	 */
	public XDBDumper(Properties p) {
		super(p);		
	}
	
	/**
	 * Overridding...
	 */
	@Override
	public <E extends Entry> void dump(E e) throws DumperException {
        try {

        	if (e instanceof XEntry) {
	        	XEntry x= (XEntry)e;
	
	        	PreparedStatement ps = this.getPs();
	        	
	            // just in case
	            ps.clearParameters();
	            // following the order we set parameter
	            // timestamp, message, severity, classname, name, personal_key
	            ps.setTimestamp(1, new java.sql.Timestamp(e.getTimestamp()));
	            ps.setString(2, e.getMessage());
	            ps.setString(3, e.getSeverity().toString());
	            ps.setString(4, e.getClassname());
	            ps.setString(5, e.getName());        
	            ps.setString(6, x.getPersonalKey());
	            
	            // ready to execute
	            ps.execute();            
        	}
        } catch (Exception ex) {
            throw new DumperException(ex);
        }		
	}


}


